
<template>
  <div>
    <select-area @selectedArea="selectedArea" />
    
    <van-field v-model="searchAddr" center clearable label="查询地址" placeholder="请输入关键词" >
      <van-button slot="button" size="small" type="danger" @click="addHotel">新增</van-button>
    </van-field>
    <van-field v-model="searchHotel" center clearable label="酒店名称" placeholder="请输入关键词" >
      <van-button slot="button" size="small" type="primary" @click="getLists">查询</van-button>
    </van-field>

    <van-swipe-cell v-for="(i,index) in items" :key="index">
      <van-panel :title="i.Wh_hotel.addr" :status="i.Dicts.name">
        <p>联系电话:{{i.Wh_hotel.conn_phone}},{{i.Wh_hotel.conn_person}}-可安排{{i.Wh_hotel.room_num}}
          -已安排{{i.Wh_hotel.checkin_num}},{{i.Wh_hotel.remark}}</p>
        <div slot="footer">
              <van-button size="mini">查看详情</van-button>
              <van-button size="mini" @click="modifyRoomNum(i.Wh_hotel)">修改房间数量</van-button>
              <van-button size="mini" @click="modify(i.Wh_hotel)" >编辑信息</van-button>
              <span>入住申请：2/3</span>
        </div>
      </van-panel>
    </van-swipe-cell>
    <van-dialog v-model="showLogin" title="登录/注册" :lazy-render="false" :showConfirmButton="false" show-cancel-button>
        <login @onLogin="onLogin" />
    </van-dialog>
    <van-dialog v-model="showHotel" title="新房源" :lazy-render="false" :showConfirmButton="false" show-cancel-button>
        <hotel @onAdded="onAdded"/>
    </van-dialog>
    <van-dialog v-model="showModifyRoomNum" title="标题" show-cancel-button @confirm="onModify">
      <van-field
        v-model="roomNum"  label="房间数量"
        :rules="[{ required: true, message: '请填写房间数量' }]">
      </van-field>
    </van-dialog>
    <van-dialog v-model="showModify" title="管理附近医院信息" :lazy-render="false" :showConfirmButton="false" show-cancel-button>
        <man-hospitals :hotel="hotel" />
    </van-dialog>
  </div>
</template>

<script>
  import { get } from "@/api/common";
  import SelectArea from "../components/SelectArea";
  import ManHospitals from "./man_hospitals";
  import Hotel from "./hotel";
  import Login from "../components/Login";
  import { Toast,Dialog } from 'vant';

  export default {
    components: {
      SelectArea,
      ManHospitals,
      Hotel,
      Login,
    },
    data() {
      return {
        searchAddr: '',
        searchHotel: '',
        areaValue: 0,
        items: [],
        roomNum: 0,
        hotel: {},
        showLogin: false,
        showHotel: false,
        showModifyRoomNum: false,
        showModify: false,
      }
    },
    mounted() {
      this.getLists();
    },
    methods: {
      // 新增酒店
      addHotel() {
        if(this.$store.state.loginId!='zyz') {
          this.hotel = {};
          this.showHotel = true;
          this.showLogin = false;
        }
        else {
          this.showHotel = false;
          this.showLogin = true;
        }
      },
      modifyRoomNum(item) {
        this.roomNum = item.room_num;
        this.showModifyRoomNum = true;
      },
      modify(item) {
        this.hotel = item;
        this.showModify = true;
      },
      onModify() {
        console.log(this.roomNum);
      },
      selectedArea(value) {
        this.areaValue = value;
      },
      // 登录后
      onLogin(value) {
        //this.$router.push({path:'/apply'});
        this.showLogin = false;
        this.showHotel = true;
      },
      //增加申请后
      onAdded(value) {
        Toast('增加申请后'+value);
        this.showApply = false;
      },
      // 调用api获得当前选择的申请列表
      getLists(){
        let body = {
                  '@column': 'id,name,addr,conn_person,conn_phone,room_num,checkin_num,checked,checkin_area,remark',
                  '@order': 'createdate',
                  };
        if(this.areaValue>0)
          body['checkin_area'] = this.areaValue;
        let params = {'[]': {
                'Wh_hotel': body,
                'Dicts':{
                  '@column': 'value,name',
                  'value@': '/Wh_hotel/checkin_area',
                  'object': 'wh_hotel',
                  'field': 'checkin_area'
                }
              }
            };
        get(params)
          .then( res=> {
            this.items = res.data["[]"];
          })
          .catch(function (error){
              console.log(error);
          });
      },
    }
  }
</script>

<style scoped>
p{
  padding-left:10px;
}
</style>
  